package com.etc.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Random;

public class Career implements Serializable{

	private static final long serialVersionUID = -4878036309896341813L;
	private String careerId;  //角色属性编号
	private CareerClassify classify;  //角色职业
	private int startHeal;      //初始生命值
	private int startImage;     //初始魔法值
	private int startAttack;     //初始攻击力
	private int startCrit;      //初始暴击
	private int startDefense;    //初始防御值
	private int startSpeed;      //初始速度
	private ArrayList<Skill> skills;   //初始技能，一个职业附带5个技能
	Random ran = new Random();
	int i = 0;
	
	//结束回合，减少回合数
	public String endRound(Role role, Role enemy) {
		String endMsg = "";
		String ifnull = "";
		for (Skill skill : skills) {   
			if(skill.availability>0) {   //如果可用度大于0，表示技能不可用，一个回合后技能可用度减少
			   skill.setAvailability(skill.availability-1);
			}
			
			//下面两个判断是为了显示什么技能已经结束了，并且将减少的属性增加回来，或者增加的属性减少
			if(skill.type.substring(0, 1).equals("增")) {
				ifnull = reduceAttr(role, skill);//减少对应的属性
				if(!ifnull.equals("")) {
					endMsg = endMsg + "#" + ifnull;
				}
			}
			else if(skill.type.substring(0, 1).equals("减")) {
				ifnull = addAttr(enemy, skill); //增加对应的属性
				if(!ifnull.equals("")) {
					endMsg = endMsg + "#" + ifnull;
				}
			}
			
			if(skill.availability == 0) {
				skill.haveUse = false;
			}
		}
		return endMsg;
	}
	//回合结束，需要增加所减少的属性
	public String addAttr(Role enemy, Skill skill) {
		String endMsg = "";
		if(skill.availability==(skill.skillCd-skill.duration) && skill.type.equals("减伤技能") && skill.haveUse) {
			endMsg = skill.skillName+"技能结束";
			enemy.setAttack(enemy.getAttack()+skill.attrAttack);
		} 
		else if(skill.availability==(skill.skillCd-skill.duration) && skill.type.equals("减暴技能") && skill.haveUse) {
			endMsg = skill.skillName+"技能结束";
			enemy.setCritical(enemy.getCritical()+skill.attrCrit);
		} 
		else if(skill.availability==(skill.skillCd-skill.duration) && skill.type.equals("减防技能") && skill.haveUse) {
			endMsg = skill.skillName+"技能结束";
			enemy.setDefense(enemy.getDefense()+skill.attrDefense);
		} 
		else if(skill.availability==(skill.skillCd-skill.duration) && skill.type.equals("减速技能") && skill.haveUse) {
			endMsg = skill.skillName+"技能结束";
			enemy.setSpeed(enemy.getSpeed()+skill.attrSpeed);
		}
		return endMsg;
	}
	//回合结束，需要减少所增加的属性
	public String reduceAttr(Role role, Skill skill) {
		//判断是否技能为可用，并且是已经用过的技能才能这样减少
		String endMsg = "";
		//skill.availability==(skill.skillCd-skill.duration)表示空档期，持续时间到了并且还在CD中
		//skill.haveUse技能使用过才能进去下面的判断
		if(skill.availability==(skill.skillCd-skill.duration) && skill.type.equals("增伤技能") && skill.haveUse) {
			endMsg = skill.skillName+"技能结束";
			role.setAttack(role.getAttack()-skill.attrAttack);
		}
		else if(skill.availability==(skill.skillCd-skill.duration) && skill.type.equals("增血技能") && skill.haveUse) {
			endMsg = skill.skillName+"技能结束";
			role.setHeal(role.getHeal()-skill.attrHeal);
		}
		else if(skill.availability==(skill.skillCd-skill.duration) && skill.type.equals("增蓝技能") && skill.haveUse) {
			endMsg = skill.skillName+"技能结束";
			role.setImage(role.getImage()-skill.attrImage);
		}
		else if(skill.availability==(skill.skillCd-skill.duration) && skill.type.equals("增暴技能") && skill.haveUse) {
			endMsg = skill.skillName+"技能结束";
			role.setCritical(role.getCritical()-skill.attrCrit);
		}
		else if(skill.availability==(skill.skillCd-skill.duration) && skill.type.equals("增防技能") && skill.haveUse) {
			endMsg = skill.skillName+"技能结束";
			role.setDefense(role.getDefense()-skill.attrDefense);
		}
		else if(skill.availability==(skill.skillCd-skill.duration) && skill.type.equals("增速技能") && skill.haveUse) {
			endMsg = skill.skillName+"技能结束";
			role.setSpeed(role.getSpeed()-skill.attrSpeed);
		}
		return endMsg;
	}
	
	public String getCareerId() {
		return careerId;
	}
	public void setCareerId(String careerId) {
		this.careerId = careerId;
	}
	public CareerClassify getClassify() {
		return classify;
	}
	public void setClassify(CareerClassify classify) {
		this.classify = classify;
	}
	public int getStartHeal() {
		return startHeal;
	}
	public void setStartHeal(int startHeal) {
		this.startHeal = startHeal;
	}
	public int getStartImage() {
		return startImage;
	}
	public void setStartImage(int startImage) {
		this.startImage = startImage;
	}
	public int getStartAttack() {
		return startAttack;
	}
	public void setStartAttack(int startAttack) {
		this.startAttack = startAttack;
	}
	public int getStartCrit() {
		return startCrit;
	}
	public void setStartCrit(int startCrit) {
		this.startCrit = startCrit;
	}
	public int getStartDefense() {
		return startDefense;
	}
	public void setStartDefense(int startDefense) {
		this.startDefense = startDefense;
	}
	public int getStartSpeed() {
		return startSpeed;
	}
	public void setStartSpeed(int startSpeed) {
		this.startSpeed = startSpeed;
	}
	public ArrayList<Skill> getSkills() {
		return skills;
	}
	public void setSkills(ArrayList<Skill> skills) {
		this.skills = skills;
	}
	public Career(String careerId, CareerClassify classify, int startHeal, int startImage, int startAttack,
			int startCrit, int startDefense, int startSpeed, ArrayList<Skill> skills) {
		super();
		this.careerId = careerId;
		this.classify = classify;
		this.startHeal = startHeal;
		this.startImage = startImage;
		this.startAttack = startAttack;
		this.startCrit = startCrit;
		this.startDefense = startDefense;
		this.startSpeed = startSpeed;
		this.skills = skills;
	}
	public Career() {
		super();
	}
	@Override
	public String toString() {
		return "Career [careerId=" + careerId + ", classify=\n" + classify + ",\n startHeal=" + startHeal + ", startImage="
				+ startImage + ", startAttack=" + startAttack + ", startCrit=" + startCrit + ", startDefense="
				+ startDefense + ", startSpeed=" + startSpeed + ", \nskills=" + skills + "]";
	}
	
	
}
